<!DOCTYPE html>
<html>
<head>
    <title>Register</title>
</head>
<body>
    <h1>注册</h1>
    <form id="registerForm">
        <input type="text" name="login_name" placeholder="Username" required />
        <input type="password" name="password" placeholder="Password" required />
        <button type="submit">注册</button>
    </form>
    
    <script>
        document.getElementById('registerForm').onsubmit = async (e) => {
            e.preventDefault();
            const formData = new FormData(e.target);
            const data = Object.fromEntries(formData);
            await fetch('/users/register', { method: 'POST', body: JSON.stringify(data), headers: { 'Content-Type': 'application/json' } });
            alert('Registration successful! Redirecting to login page.');
            window.location.href = 'login.html'; // 完成注册后跳转回登录页面
        };
    </script>
</body>
</html>